﻿namespace WMS6.Web
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web;
    using WMS6.Web.BaseInfoServiceRef;

    public class BaseInfoServiceClientProxy : BasePage
    {
        public string Delete(List<string> IDS, string className)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BaseInfoServiceClient client = new BaseInfoServiceClient("WSHttpBinding_IBaseInfoService");
            try
            {
                result = client.Delete(IDS, className, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public DataSet GetAllInfo(string className)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            BaseInfoServiceClient client = new BaseInfoServiceClient("WSHttpBinding_IBaseInfoService");
            try
            {
                ds = client.GetAllInfo(className, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public object GetInfoByID(string id, string className)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            object obj = null;
            BaseInfoServiceClient client = new BaseInfoServiceClient("WSHttpBinding_IBaseInfoService");
            try
            {
                obj = client.GetInfoByID(id, className, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return obj;
        }

        public DataSet GetInfoByQueryEntity(object obj, string className)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            BaseInfoServiceClient client = new BaseInfoServiceClient("WSHttpBinding_IBaseInfoService");
            try
            {
                ds = client.GetInfoByQueryEntity(obj, className, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public static BaseInfoServiceClientProxy GetInstance()
        {
            return new BaseInfoServiceClientProxy();
        }

        private PubParasInfo InitPubParasInfo()
        {
            if (base.UserInfo != null)
            {
                return new PubParasInfo { UserID = base.UserInfo.UserID, UserLanguage = base.UserInfo.Preference.Lang, CurrentWH = base.UserInfo.CurrentWH };
            }
            HttpContext.Current.Response.Redirect("../Login.aspx?from=Logout", true);
            return null;
        }

        public string Insert(object obj, string className)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BaseInfoServiceClient client = new BaseInfoServiceClient("WSHttpBinding_IBaseInfoService");
            try
            {
                result = client.Insert(obj, className, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        private void test()
        {
            HttpContext.Current.Response.Write("<script language=javascript>top.location.href='../Login.aspx'</script>");
            HttpContext.Current.Response.Write("<script language=javascript>window.location.href='../Login.aspx'</script>");
            HttpContext.Current.Response.Write("<script language=javascript>window.parent.close()</script>");
        }

        public string Update(object obj, string className)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BaseInfoServiceClient client = new BaseInfoServiceClient("WSHttpBinding_IBaseInfoService");
            try
            {
                result = client.Update(obj, className, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }
    }
}

